package com.example.util;

/**
 * 定义不同情景下，各种响应体返回的具体值
 *
 */
public class Response {

    private static String SUCCESS="success";

    private static String FAIL="fail";

    //创建不同场景下的返回结果对象

    //1.成功执行，没有要返回的数据
    public static <T> ResponseResult<T> createOkResp()
    {
           return new ResponseResult<T>(StatusCode.SUCCESS.code,SUCCESS,null);
    }

    //2.成功执行，需要返回数据
    public static <T> ResponseResult<T> createOkResp(T data)
    {
        return new ResponseResult<T>(StatusCode.SUCCESS.code,SUCCESS,data);
    }

    //3.成功执行，需要返回消息和数据
    public static <T> ResponseResult<T> createOkResp(String msg, T data)
    {
        return new ResponseResult<T>(StatusCode.SUCCESS.code,msg,data);
    }

    //4.成功执行，需要消息参数，无数据
    public static <T> ResponseResult<T> createOkResp(String msg)
    {
        return new ResponseResult<T>(StatusCode.SUCCESS.code,msg,null);
    }

    //1.失败执行
    public static <T> ResponseResult<T> createFailResp()
    {
        return new ResponseResult<T>(StatusCode.SERVER_ERROR.code,FAIL,null);
    }

    //2.失败执行
    public static <T> ResponseResult<T> createFailResp(String msg)
    {
        return new ResponseResult<T>(500,msg,null);
    }

    //3.其它失败执行
    public static <T> ResponseResult<T> createFailResp(int code, String msg)
    {
        return new ResponseResult<T>(code,msg,null);
    }

    //4.其他执行
    public static <T> ResponseResult<T> createResp(int code, String msg, T data)
    {
        return new ResponseResult<T>(code,msg,data);
    }

}
